/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flgrCoreMalloc.h"
#include "flgrCoreData.h"
#include "flgrCoreDispatch.h"
#include "flgrCoreIO.h"
#include "flgrCoreDataIO.h"

/*!
 * \addtogroup group_fulguro_core_array
 * @{
 */



//////////////////////////////////////////////////////
// Macro for flgr1d_set_data_vector
//////////////////////////////////////////////////////
#define FLGR_MACRO_SET_DATA1D_VECTOR(dtype)				\
  dtype *array_s = (dtype*) (vct->array);				\
  dtype *array_d = (dtype*) (dat->array);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_set_data_array_vector_##dtype(array_d, array_s, vct->spp, pos)
  
void flgr1d_set_data_vector_fgBIT(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgBIT);
}
void flgr1d_set_data_vector_fgUINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgUINT8);
}
void flgr1d_set_data_vector_fgUINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgUINT16);
}
void flgr1d_set_data_vector_fgUINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgUINT32);
}
void flgr1d_set_data_vector_fgINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgINT8);
}
void flgr1d_set_data_vector_fgINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgINT16);
}
void flgr1d_set_data_vector_fgINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgINT32);
}
void flgr1d_set_data_vector_fgFLOAT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgFLOAT32);
}
void flgr1d_set_data_vector_fgFLOAT64(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA1D_VECTOR(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Set a vector at a specific position in an 1D Array
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_set_data_vector(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((pos<0) || (pos>=dat->length)) {
    POST_WARNING("position out of the array : %d!\n",pos);
    return FLGR_RET_UNDEFINED_ERROR;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type,flgr1d_set_data_vector,dat,pos,vct);
}





//////////////////////////////////////////////////////
// Macro for flgr1d_get_data_vector
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA1D_VECTOR(dtype)				\
  dtype *array_s = (dtype*) (dat->array);				\
  dtype *array_d = (dtype*) (vct->array);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  pos = flgr_normalize_coordinate(pos,dat->length);			\
  flgr_get_data_array_vector_##dtype(array_d, array_s, vct->spp, pos)

void flgr1d_get_data_vector_fgBIT(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgBIT);
}
void flgr1d_get_data_vector_fgUINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgUINT8);
}
void flgr1d_get_data_vector_fgUINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgUINT16);
}
void flgr1d_get_data_vector_fgUINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgUINT32);
}
void flgr1d_get_data_vector_fgINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgINT8);
}
void flgr1d_get_data_vector_fgINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgINT16);
}
void flgr1d_get_data_vector_fgINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgINT32);
}
void flgr1d_get_data_vector_fgFLOAT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgFLOAT32);
}
void flgr1d_get_data_vector_fgFLOAT64(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Get a vector at a specific position in an 1D Array
 *
 * The position in the array is normalized (eg if pos==-2 then pos=1)
 *
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_get_data_vector(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type,flgr1d_get_data_vector,dat,pos,vct);
}






//////////////////////////////////////////////////////
// Macro for flgr1d_get_data_vector_no_norm
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(dtype)			\
  dtype *array_s = (dtype*) (dat->array);				\
  dtype *array_d = (dtype*) (vct->array);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_get_data_array_vector_##dtype(array_d, array_s, vct->spp, pos)

void flgr1d_get_data_vector_no_norm_fgBIT(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgBIT);
}
void flgr1d_get_data_vector_no_norm_fgUINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgUINT8);
}
void flgr1d_get_data_vector_no_norm_fgUINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgUINT16);
}
void flgr1d_get_data_vector_no_norm_fgUINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgUINT32);
}
void flgr1d_get_data_vector_no_norm_fgINT8(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgINT8);
}
void flgr1d_get_data_vector_no_norm_fgINT16(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgINT16);
}
void flgr1d_get_data_vector_no_norm_fgINT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgINT32);
}
void flgr1d_get_data_vector_no_norm_fgFLOAT32(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgFLOAT32);
}
void flgr1d_get_data_vector_no_norm_fgFLOAT64(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA1D_VECTOR_NO_NORM(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Get a vector at a specific position in an 1D Array
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_get_data_vector_no_norm(FLGR_Data1D *dat, int pos, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((pos<0) || (pos>=dat->length)) {
    POST_WARNING("position out of the array : %d!\n",pos);
    return FLGR_RET_UNDEFINED_ERROR;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type,flgr1d_get_data_vector_no_norm,dat,pos,vct);
}










//////////////////////////////////////////////////////
// Macro for flgr2d_set_data_vector
//////////////////////////////////////////////////////
#define FLGR_MACRO_SET_DATA2D_VECTOR(dtype)				\
  dtype *array_s = (dtype*) (vct->array);				\
  dtype *array_d = (dtype*) (dat->array[row]);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_set_data_array_vector_##dtype(array_d, array_s, vct->spp, col)

void flgr2d_set_data_vector_fgBIT(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgBIT);
}
void flgr2d_set_data_vector_fgUINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgUINT8);
}
void flgr2d_set_data_vector_fgUINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgUINT16);
}
void flgr2d_set_data_vector_fgUINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgUINT32);
}
void flgr2d_set_data_vector_fgINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgINT8);
}
void flgr2d_set_data_vector_fgINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgINT16);
}
void flgr2d_set_data_vector_fgINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgINT32);
}
void flgr2d_set_data_vector_fgFLOAT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgFLOAT32);
}
void flgr2d_set_data_vector_fgFLOAT64(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_SET_DATA2D_VECTOR(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Set a vector at a specific position in an 2D Array
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer representing the row position in the array
 *  @param col   : an integer representing the column position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_set_data_vector(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((row<0) || (row>=dat->size_y)) {
    POST_WARNING("row position out of the array : %d!\n",row);
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((col<0) || (col>=dat->size_x)) {
    POST_WARNING("row position out of the array : %d!\n",col);
    return FLGR_RET_UNDEFINED_ERROR;
  }


  FLGR_DISPATCH_PROCEDURE(dat->type,flgr2d_set_data_vector,dat,row,col,vct);
}





//////////////////////////////////////////////////////
// Macro for flgr2d_get_data_vector
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA2D_VECTOR(dtype)				\
  dtype *array_s;							\
  dtype *array_d = (dtype*) (vct->array);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  row = flgr_normalize_coordinate(row,dat->size_y);			\
  col = flgr_normalize_coordinate(col,dat->size_x);			\
  array_s = (dtype*) (dat->array[row]);					\
  flgr_get_data_array_vector_##dtype(array_d, array_s, vct->spp, col)

void flgr2d_get_data_vector_fgBIT(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgBIT);
}
void flgr2d_get_data_vector_fgUINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgUINT8);
}
void flgr2d_get_data_vector_fgUINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgUINT16);
}
void flgr2d_get_data_vector_fgUINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgUINT32);
}
void flgr2d_get_data_vector_fgINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgINT8);
}
void flgr2d_get_data_vector_fgINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgINT16);
}
void flgr2d_get_data_vector_fgINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgINT32);
}
void flgr2d_get_data_vector_fgFLOAT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgFLOAT32);
}
void flgr2d_get_data_vector_fgFLOAT64(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Get a vector at a specific position in an 2D Array
 *
 * The position in the array is normalized (eg if rows==-2 then row=1)
 *
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer representing the row position in the array
 *  @param col   : an integer representing the column position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_get_data_vector(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type,flgr2d_get_data_vector,dat,row,col,vct);
}






//////////////////////////////////////////////////////
// Macro for flgr2d_get_data_vector_no_norm
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(dtype)			\
  dtype *array_s = (dtype*) (dat->array[row]);				\
  dtype *array_d = (dtype*) (vct->array);				\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_get_data_array_vector_##dtype(array_d, array_s, vct->spp, col)

void flgr2d_get_data_vector_no_norm_fgBIT(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgBIT);
}
void flgr2d_get_data_vector_no_norm_fgUINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgUINT8);
}
void flgr2d_get_data_vector_no_norm_fgUINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgUINT16);
}
void flgr2d_get_data_vector_no_norm_fgUINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgUINT32);
}
void flgr2d_get_data_vector_no_norm_fgINT8(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgINT8);
}
void flgr2d_get_data_vector_no_norm_fgINT16(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgINT16);
}
void flgr2d_get_data_vector_no_norm_fgINT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgINT32);
}
void flgr2d_get_data_vector_no_norm_fgFLOAT32(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgFLOAT32);
}
void flgr2d_get_data_vector_no_norm_fgFLOAT64(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_MACRO_GET_DATA2D_VECTOR_NO_NORM(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! Get a vector at a specific position in an 2D Array
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer representing the row position in the array
 *  @param col   : an integer representing the column position in the array
 *  @param vct : pointer to a FLGR_Vector
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_get_data_vector_no_norm(FLGR_Data2D *dat, int row, int col, FLGR_Vector *vct) {
  FLGR_DECLARE_FUNCTION;

  if((dat==NULL) || (vct==NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->spp != vct->spp) {
    POST_ERROR("Data and Vector don't have the same Samples Per Pixel\n");
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((row<0) || (row>=dat->size_y)) {
    POST_WARNING("row position out of the array : %d!\n",row);
    return FLGR_RET_UNDEFINED_ERROR;
  }

  if((col<0) || (col>=dat->size_x)) {
    POST_WARNING("column position out of the array : %d!\n",col);
    return FLGR_RET_UNDEFINED_ERROR;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type,flgr2d_get_data_vector_no_norm,dat,row,col,vct);
}













//////////////////////////////////////////////////////
// Macro for flgr1d_set_data_dtype
//////////////////////////////////////////////////////
#define FLGR_MACRO_SET_DATA1D(dtype)					\
  int k;								\
  FLGR_DECLARE_FUNCTION;						\
									\
  POST_WARNING("Deprecated\n");						\
  if(pos<0) {								\
    POST_WARNING("position in 1D array is negative: %d!\n",pos);	\
    return;								\
  }									\
  if(pos>=dat->length) {						\
    POST_WARNING("position in 1D array is too large: %d!\n",pos);	\
    return;								\
  }									\
  if(dat->spp < 1) {							\
    POST_WARNING("Vector size could not < 1\n");			\
    return;								\
  }									\
  pos *= dat->spp;							\
  for(k=0 ; k<dat->spp ; k++,value++)					\
    flgr1d_set_data_array_##dtype(dat->array, pos+k, *value);		\
									\
  return


void flgr1d_set_data_fgBIT(FLGR_Data1D *dat, int pos, fgBIT *value) {
  FLGR_MACRO_SET_DATA1D(fgBIT);
}
void flgr1d_set_data_fgUINT8(FLGR_Data1D *dat, int pos, fgUINT8 *value) {
  FLGR_MACRO_SET_DATA1D(fgUINT8);
}
void flgr1d_set_data_fgUINT16(FLGR_Data1D *dat, int pos, fgUINT16 *value) {
  FLGR_MACRO_SET_DATA1D(fgUINT16);
}
void flgr1d_set_data_fgUINT32(FLGR_Data1D *dat, int pos, fgUINT32 *value) {
  FLGR_MACRO_SET_DATA1D(fgUINT32);
}
void flgr1d_set_data_fgINT8(FLGR_Data1D *dat, int pos, fgINT8 *value) {
  FLGR_MACRO_SET_DATA1D(fgINT8);
}
void flgr1d_set_data_fgINT16(FLGR_Data1D *dat, int pos, fgINT16 *value) {
  FLGR_MACRO_SET_DATA1D(fgINT16);
}
void flgr1d_set_data_fgINT32(FLGR_Data1D *dat, int pos, fgINT32 *value) {
  FLGR_MACRO_SET_DATA1D(fgINT32);
}
void flgr1d_set_data_fgFLOAT32(FLGR_Data1D *dat, int pos, fgFLOAT32 *value) {
  FLGR_MACRO_SET_DATA1D(fgFLOAT32);
}
void flgr1d_set_data_fgFLOAT64(FLGR_Data1D *dat, int pos, fgFLOAT64 *value) {
  FLGR_MACRO_SET_DATA1D(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Set a value at a specific position in an 1D Array
 *  @warning this function don't check if image is a multichannel one.
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param value : pointer to a value
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_set_data_ptr(FLGR_Data1D *dat, int pos, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->type==FLGR_UINT8) {
    flgr1d_set_data_fgUINT8(dat,pos,(fgUINT8*) value);
    
  }else if(dat->type==FLGR_UINT16) {
    flgr1d_set_data_fgUINT16(dat,pos,(fgUINT16*) value);

  }else if(dat->type==FLGR_UINT32) {
    flgr1d_set_data_fgUINT32(dat,pos,(fgUINT32*) value);

  }else if(dat->type==FLGR_INT8) {
    flgr1d_set_data_fgINT8(dat,pos,(fgINT8*) value);

  }else if(dat->type==FLGR_INT16) {
    flgr1d_set_data_fgINT16(dat,pos,(fgINT16*) value);

  }else if(dat->type==FLGR_INT32) {
    flgr1d_set_data_fgINT32(dat,pos,(fgINT32*) value);

  }else if(dat->type==FLGR_FLOAT32) {
    flgr1d_set_data_fgFLOAT32(dat,pos,(fgFLOAT32*) value);

  }else if(dat->type==FLGR_FLOAT64) {
    flgr1d_set_data_fgFLOAT64(dat,pos,(fgFLOAT64*) value);

  }else if(dat->type==FLGR_BIT) {
    flgr1d_set_data_fgBIT(dat,pos,(fgBIT*) value);

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;
}

//////////////////////////////////////////////////////////////////
/*! Set a value at a specific position in an 1D Array
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param value : string representing the value
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_set_data_str(FLGR_Data1D *dat, int pos, char *value) {
  int sizeConst;
  void *val;
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  sizeConst = flgr_get_sizeof(dat->type);
  val = flgr_malloc(sizeConst*dat->spp);

  ret = flgr_parse_str_constant(dat->type,dat->spp,value, val);
  if(ret!=FLGR_RET_OK) {
    flgr_free(val);
    return ret;
  }

  ret = flgr1d_set_data_ptr(dat, pos, val);

  flgr_free(val);

  return ret;
}




  		

//////////////////////////////////////////////////////
// Macro for flgr1d_get_data_dtype
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA1D(dtype)					\
  int k;								\
  FLGR_DECLARE_FUNCTION;						\
									\
  POST_WARNING("Deprecated\n");						\
  if(dat->spp < 1) {							\
    POST_WARNING("Vector size could not < 1\n");			\
    return;								\
  }									\
									\
  pos = flgr_normalize_coordinate(pos,dat->length);			\
									\
  pos *= dat->spp;							\
									\
  for(k=0 ; k<dat->spp ; k++,value++)					\
    *value = flgr1d_get_data_array_##dtype(dat->array, pos+k);		\
									\
									\
  return

void flgr1d_get_data_fgBIT(FLGR_Data1D *dat, int pos, fgBIT *value) {
  FLGR_MACRO_GET_DATA1D(fgBIT);
}
void flgr1d_get_data_fgUINT8(FLGR_Data1D *dat, int pos, fgUINT8 *value) {
  FLGR_MACRO_GET_DATA1D(fgUINT8);
}
void flgr1d_get_data_fgUINT16(FLGR_Data1D *dat, int pos, fgUINT16 *value) {
  FLGR_MACRO_GET_DATA1D(fgUINT16);
}
void flgr1d_get_data_fgUINT32(FLGR_Data1D *dat, int pos, fgUINT32 *value) {
  FLGR_MACRO_GET_DATA1D(fgUINT32);
}
void flgr1d_get_data_fgINT8(FLGR_Data1D *dat, int pos, fgINT8 *value) {
  FLGR_MACRO_GET_DATA1D(fgINT8);
}
void flgr1d_get_data_fgINT16(FLGR_Data1D *dat, int pos, fgINT16 *value) {
  FLGR_MACRO_GET_DATA1D(fgINT16);
}
void flgr1d_get_data_fgINT32(FLGR_Data1D *dat, int pos, fgINT32 *value) {
  FLGR_MACRO_GET_DATA1D(fgINT32);
}
void flgr1d_get_data_fgFLOAT32(FLGR_Data1D *dat, int pos, fgFLOAT32 *value) {
  FLGR_MACRO_GET_DATA1D(fgFLOAT32);
}
void flgr1d_get_data_fgFLOAT64(FLGR_Data1D *dat, int pos, fgFLOAT64 *value) {
  FLGR_MACRO_GET_DATA1D(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! get a value at a specific position in an 1D Array.
 *  If the position is out of the matrix, pos will be recalculated to reflect a signal unfolded
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param value : pointer to a value
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_get_data_ptr(FLGR_Data1D *dat, int pos, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->type==FLGR_UINT8) {
    flgr1d_get_data_fgUINT8(dat,pos,(fgUINT8*) value);
    
  }else if(dat->type==FLGR_UINT16) {
    flgr1d_get_data_fgUINT16(dat,pos,(fgUINT16*) value);

  }else if(dat->type==FLGR_UINT32) {
    flgr1d_get_data_fgUINT32(dat,pos,(fgUINT32*) value);

  }else if(dat->type==FLGR_INT8) {
    flgr1d_get_data_fgINT8(dat,pos,(fgINT8*) value);

  }else if(dat->type==FLGR_INT16) {
    flgr1d_get_data_fgINT16(dat,pos,(fgINT16*) value);

  }else if(dat->type==FLGR_INT32) {
    flgr1d_get_data_fgINT32(dat,pos,(fgINT32*) value);

  }else if(dat->type==FLGR_FLOAT32) {
    flgr1d_get_data_fgFLOAT32(dat,pos,(fgFLOAT32*) value);

  }else if(dat->type==FLGR_FLOAT64) {
    flgr1d_get_data_fgFLOAT64(dat,pos,(fgFLOAT64*) value);

  }else if(dat->type==FLGR_BIT) {
    flgr1d_get_data_fgBIT(dat,pos,(fgBIT*) value);

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;
}




//////////////////////////////////////////////////////
// Macro for flgr1d_get_data_dtype
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA1D_NO_NORM(dtype)				\
  int k;								\
  FLGR_DECLARE_FUNCTION;						\
									\
  POST_WARNING("Deprecated\n");						\
 									\
  if(pos<0) {								\
    POST_WARNING("value out of the array : %d!\n",pos);			\
    return;								\
  }									\
  if(pos>=dat->length) {						\
    POST_WARNING("value out of the array : %d!\n",pos);			\
    return;								\
  }									\
  pos *= dat->spp;							\
									\
  for(k=0 ; k<dat->spp ; k++,value++)					\
    *value = flgr1d_get_data_array_##dtype(dat->array, pos+k);		\


void flgr1d_get_data_no_norm_fgBIT(FLGR_Data1D *dat, int pos, fgBIT *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgBIT);
}
void flgr1d_get_data_no_norm_fgUINT8(FLGR_Data1D *dat, int pos, fgUINT8 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgUINT8);
}
void flgr1d_get_data_no_norm_fgUINT16(FLGR_Data1D *dat, int pos, fgUINT16 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgUINT16);
}
void flgr1d_get_data_no_norm_fgUINT32(FLGR_Data1D *dat, int pos, fgUINT32 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgUINT32);
}
void flgr1d_get_data_no_norm_fgINT8(FLGR_Data1D *dat, int pos, fgINT8 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgINT8);
}
void flgr1d_get_data_no_norm_fgINT16(FLGR_Data1D *dat, int pos, fgINT16 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgINT16);
}
void flgr1d_get_data_no_norm_fgINT32(FLGR_Data1D *dat, int pos, fgINT32 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgINT32);
}
void flgr1d_get_data_no_norm_fgFLOAT32(FLGR_Data1D *dat, int pos, fgFLOAT32 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgFLOAT32);
}
void flgr1d_get_data_no_norm_fgFLOAT64(FLGR_Data1D *dat, int pos, fgFLOAT64 *value) {
  FLGR_MACRO_GET_DATA1D_NO_NORM(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! get a value at a specific position in an 1D Array
 *  @param dat   : a pointer to FLGR_Data1D
 *  @param pos   : an integer representing the position in the array
 *  @param value : pointer to a value
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_get_data_no_norm_ptr(FLGR_Data1D *dat, int pos, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->type==FLGR_UINT8) {
    flgr1d_get_data_no_norm_fgUINT8(dat,pos,(fgUINT8*) value);
    
  }else if(dat->type==FLGR_UINT16) {
    flgr1d_get_data_no_norm_fgUINT16(dat,pos,(fgUINT16*) value);

  }else if(dat->type==FLGR_UINT32) {
    flgr1d_get_data_no_norm_fgUINT32(dat,pos,(fgUINT32*) value);

  }else if(dat->type==FLGR_INT8) {
    flgr1d_get_data_no_norm_fgINT8(dat,pos,(fgINT8*) value);

  }else if(dat->type==FLGR_INT16) {
    flgr1d_get_data_no_norm_fgINT16(dat,pos,(fgINT16*) value);

  }else if(dat->type==FLGR_INT32) {
    flgr1d_get_data_no_norm_fgINT32(dat,pos,(fgINT32*) value);

  }else if(dat->type==FLGR_FLOAT32) {
    flgr1d_get_data_no_norm_fgFLOAT32(dat,pos,(fgFLOAT32*) value);

  }else if(dat->type==FLGR_FLOAT64) {
    flgr1d_get_data_no_norm_fgFLOAT64(dat,pos,(fgFLOAT64*) value);

  }else if(dat->type==FLGR_BIT) {
    flgr1d_get_data_no_norm_fgBIT(dat,pos,(fgBIT*) value);

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;
}









//////////////////////////////////////////////////
// MACRO for flgr2d_set_data
//////////////////////////////////////////////////
#define FLGR_MACRO_SET_DATA2D(dtype)					\
  int k;								\
  dtype **array = (dtype **) dat->array;				\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  POST_WARNING("Deprecated\n");						\
									\
  if(row<0) {								\
    POST_WARNING("row value out of the array (row=%d)!\n",row);		\
    return;								\
  }									\
  if(col<0) {								\
    POST_WARNING("row value out of the array (column=%d)!\n",col);	\
    return;								\
  }									\
  if(row>=dat->size_y) {						\
    POST_WARNING("row value out of the array (row=%d)!\n",row);		\
    return;								\
  }									\
  if(col>=dat->size_x) {						\
    POST_WARNING("row value out of the array (column=%d)!\n",col);	\
    return;								\
  }									\
  if(dat->spp < 1) {							\
    POST_WARNING("Vector size could not < 1\n");			\
    return;								\
  }									\
									\
  col *= dat->spp;							\
  for(k=0 ; k<dat->spp ; k++,value++)					\
    flgr2d_set_data_array_##dtype(array, row,col+k, *value);		\
									\
  return 


void flgr2d_set_data_fgBIT(FLGR_Data2D *dat, int row, int col, fgBIT *value) {
  FLGR_MACRO_SET_DATA2D(fgBIT);
}
void flgr2d_set_data_fgUINT8(FLGR_Data2D *dat, int row, int col, fgUINT8 *value) {
  FLGR_MACRO_SET_DATA2D(fgUINT8);
}
void flgr2d_set_data_fgUINT16(FLGR_Data2D *dat, int row, int col, fgUINT16 *value) {
  FLGR_MACRO_SET_DATA2D(fgUINT16);
}
void flgr2d_set_data_fgUINT32(FLGR_Data2D *dat, int row, int col, fgUINT32 *value) {
  FLGR_MACRO_SET_DATA2D(fgUINT32);
}
void flgr2d_set_data_fgINT8(FLGR_Data2D *dat, int row, int col, fgINT8 *value) {
  FLGR_MACRO_SET_DATA2D(fgINT8);
}
void flgr2d_set_data_fgINT16(FLGR_Data2D *dat, int row, int col, fgINT16 *value) {
  FLGR_MACRO_SET_DATA2D(fgINT16);
}
void flgr2d_set_data_fgINT32(FLGR_Data2D *dat, int row, int col, fgINT32 *value) {
  FLGR_MACRO_SET_DATA2D(fgINT32);
}
void flgr2d_set_data_fgFLOAT32(FLGR_Data2D *dat, int row, int col, fgFLOAT32 *value) {
  FLGR_MACRO_SET_DATA2D(fgFLOAT32);
}
void flgr2d_set_data_fgFLOAT64(FLGR_Data2D *dat, int row, int col, fgFLOAT64 *value) {
  FLGR_MACRO_SET_DATA2D(fgFLOAT64);
}


//////////////////////////////////////////////////////////////////
/*! Set a value at a specific position in an 2D Array
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer for row number
 *  @param col   : an integer for column number
 *  @param value : a pointer to a variable which type corresponds with dat->type
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_set_data_ptr(FLGR_Data2D *dat, int row, int col, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }
 
  if(dat->type==FLGR_UINT8) {
    flgr2d_set_data_fgUINT8(dat,row,col,(fgUINT8*) value);
    
  }else if(dat->type==FLGR_UINT16) {
    flgr2d_set_data_fgUINT16(dat,row,col,(fgUINT16*) value);

  }else if(dat->type==FLGR_UINT32) {
    flgr2d_set_data_fgUINT32(dat,row,col,(fgUINT32*) value);

  }else if(dat->type==FLGR_INT8) {
    flgr2d_set_data_fgINT8(dat,row,col,(fgINT8*) value);

  }else if(dat->type==FLGR_INT16) {
    flgr2d_set_data_fgINT16(dat,row,col,(fgINT16*) value);

  }else if(dat->type==FLGR_INT32) {
    flgr2d_set_data_fgINT32(dat,row,col,(fgINT32*) value);

  }else if(dat->type==FLGR_FLOAT32) {
    flgr2d_set_data_fgFLOAT32(dat,row,col,(fgFLOAT32*) value);

  }else if(dat->type==FLGR_FLOAT64) {
    flgr2d_set_data_fgFLOAT64(dat,row,col,(fgFLOAT64*) value);

  }else if(dat->type==FLGR_BIT) {
    flgr2d_set_data_fgBIT(dat,row,col,(fgBIT*) value);

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;

}


//////////////////////////////////////////////////////////////////
/*! Get a value at a specific position in an 2D array
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer for row number
 *  @param col   : an integer for column number
 *  @param value : string representig the value
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_set_data_str(FLGR_Data2D *dat, int row, int col, char *value) {
  int sizeConst;
  void *val;
  FLGR_Ret ret;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  sizeConst = flgr_get_sizeof(dat->type);
  val = flgr_malloc(sizeConst*dat->spp);

  ret = flgr_parse_str_constant(dat->type,dat->spp,value, val);
  if(ret!=FLGR_RET_OK) {
    flgr_free(val);
    return ret;
  }

  ret = flgr2d_set_data_ptr(dat, row, col, val);

  flgr_free(val);

  return ret;
}






//////////////////////////////////////////////////////
// Macro for flgr1d_get_data_dtype
//////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA2D(dtype)				\
  int k;							\
  dtype **array = (dtype**)  dat->array;			\
								\
  FLGR_DECLARE_FUNCTION;					\
								\
								\
  POST_WARNING("Deprecated\n");					\
								\
  if(dat->spp < 1) {						\
    POST_WARNING("Vector size could not < 1\n");		\
    return;							\
  }								\
								\
  row = flgr_normalize_coordinate(row,dat->size_y);		\
  col = flgr_normalize_coordinate(col,dat->size_x);		\
								\
  col *= dat->spp;						\
								\
  for(k=0 ; k<dat->spp ; k++,value++)				\
    *value = flgr2d_get_data_array_##dtype(array,row,col+k);	\
  								\

void flgr2d_get_data_fgBIT(FLGR_Data2D *dat, int row, int col, fgBIT *value) {
  FLGR_MACRO_GET_DATA2D(fgBIT);
}
void flgr2d_get_data_fgUINT8(FLGR_Data2D *dat, int row, int col, fgUINT8 *value) {
  FLGR_MACRO_GET_DATA2D(fgUINT8);
}
void flgr2d_get_data_fgUINT16(FLGR_Data2D *dat, int row, int col, fgUINT16 *value) {
  FLGR_MACRO_GET_DATA2D(fgUINT16);
}
void flgr2d_get_data_fgUINT32(FLGR_Data2D *dat, int row, int col, fgUINT32 *value) {
  FLGR_MACRO_GET_DATA2D(fgUINT32);
}
void flgr2d_get_data_fgINT8(FLGR_Data2D *dat, int row, int col, fgINT8 *value) {
  FLGR_MACRO_GET_DATA2D(fgINT8);
}
void flgr2d_get_data_fgINT16(FLGR_Data2D *dat, int row, int col, fgINT16 *value) {
  FLGR_MACRO_GET_DATA2D(fgINT16);
}
void flgr2d_get_data_fgINT32(FLGR_Data2D *dat, int row, int col, fgINT32 *value) {
  FLGR_MACRO_GET_DATA2D(fgINT32);
}
void flgr2d_get_data_fgFLOAT32(FLGR_Data2D *dat, int row, int col, fgFLOAT32 *value) {
  FLGR_MACRO_GET_DATA2D(fgFLOAT32);
}
void flgr2d_get_data_fgFLOAT64(FLGR_Data2D *dat, int row, int col, fgFLOAT64 *value) {
  FLGR_MACRO_GET_DATA2D(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Get a pixel value by specifying coordinates. Unfold data if coordinate are outside
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer for row number
 *  @param col   : an integer for column number
 *  @param value : pointer to the value (the type of the original value must fit with dat->type)
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_get_data_ptr(FLGR_Data2D *dat, int row, int col, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->type==FLGR_UINT8) {
    flgr2d_get_data_fgUINT8(dat,row,col,((fgUINT8*) value));

  }else if(dat->type==FLGR_UINT16) {
    flgr2d_get_data_fgUINT16(dat,row,col,((fgUINT16*) value));

  }else if(dat->type==FLGR_UINT32) {
    flgr2d_get_data_fgUINT32(dat,row,col,((fgUINT32*) value));

  }else if(dat->type==FLGR_INT8) {
    flgr2d_get_data_fgINT8(dat,row,col,((fgINT8*) value));

  }else if(dat->type==FLGR_INT16) {
    flgr2d_get_data_fgINT16(dat,row,col,((fgINT16*) value));

  }else if(dat->type==FLGR_INT32) {
    flgr2d_get_data_fgINT32(dat,row,col,((fgINT32*) value));

  }else if(dat->type==FLGR_FLOAT32) {
    flgr2d_get_data_fgFLOAT32(dat,row,col,((fgFLOAT32*) value));

  }else if(dat->type==FLGR_FLOAT64) {
    flgr2d_get_data_fgFLOAT64(dat,row,col,((fgFLOAT64*) value));

  }else if(dat->type==FLGR_BIT) {
    flgr2d_get_data_fgBIT(dat,row,col,((fgBIT*) value));

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }
  
  return FLGR_RET_OK;
}



///////////////////////////////////////////////////////////
// MACRO for flgr2d_get_data_no_norm
///////////////////////////////////////////////////////////
#define FLGR_MACRO_GET_DATA2D_NO_NORM(dtype)				\
  int k;								\
  dtype **array = (dtype**)  dat->array;				\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
									\
  POST_WARNING("Deprecated\n");						\
									\
  if(row<0) {								\
    POST_WARNING("row value out of the array (row=%d)!\n",row);		\
    return;								\
  }									\
  if(col<0) {								\
    POST_WARNING("row value out of the array (column=%d)!\n",col);	\
    return;								\
  }									\
  if(row>=dat->size_y) {						\
    POST_WARNING("row value out of the array (row=%d)!\n",row);		\
    return;								\
  }									\
  if(col>=dat->size_x) {						\
    POST_WARNING("row value out of the array (column=%d)!\n",col);	\
    return;								\
  }									\
  if(dat->spp < 1) {							\
    POST_WARNING("Vector size could not < 1\n");			\
    return;								\
  }									\
									\
  col *= dat->spp;							\
									\
  for(k=0 ; k<dat->spp ; k++,value++)					\
    *value = flgr2d_get_data_array_##dtype(array,row,col+k);		\
									\
  return 


void flgr2d_get_data_no_norm_fgBIT(FLGR_Data2D *dat, int row, int col, fgBIT *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgBIT);
}
void flgr2d_get_data_no_norm_fgUINT8(FLGR_Data2D *dat, int row, int col, fgUINT8 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgUINT8);
}
void flgr2d_get_data_no_norm_fgUINT16(FLGR_Data2D *dat, int row, int col, fgUINT16 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgUINT16);
}
void flgr2d_get_data_no_norm_fgUINT32(FLGR_Data2D *dat, int row, int col, fgUINT32 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgUINT32);
}
void flgr2d_get_data_no_norm_fgINT8(FLGR_Data2D *dat, int row, int col, fgINT8 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgINT8);
}
void flgr2d_get_data_no_norm_fgINT16(FLGR_Data2D *dat, int row, int col, fgINT16 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgINT16);
}
void flgr2d_get_data_no_norm_fgINT32(FLGR_Data2D *dat, int row, int col, fgINT32 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgINT32);
}
void flgr2d_get_data_no_norm_fgFLOAT32(FLGR_Data2D *dat, int row, int col, fgFLOAT32 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgFLOAT32);
}
void flgr2d_get_data_no_norm_fgFLOAT64(FLGR_Data2D *dat, int row, int col, fgFLOAT64 *value) {
  FLGR_MACRO_GET_DATA2D_NO_NORM(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Get a pixel value
 *  @param dat   : a pointer to FLGR_Data2D
 *  @param row   : an integer for row number
 *  @param col   : an integer for column number
 *  @param value : pointer to the value (the type of the original value must fit with dat->type)
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_get_data_no_norm_ptr(FLGR_Data2D *dat, int row, int col, void *value) {
  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(dat->type==FLGR_UINT8) {
    flgr2d_get_data_no_norm_fgUINT8(dat,row,col,((fgUINT8*) value));

  }else if(dat->type==FLGR_UINT16) {
    flgr2d_get_data_no_norm_fgUINT16(dat,row,col,((fgUINT16*) value));

  }else if(dat->type==FLGR_UINT32) {
    flgr2d_get_data_no_norm_fgUINT32(dat,row,col,((fgUINT32*) value));

  }else if(dat->type==FLGR_INT8) {
    flgr2d_get_data_no_norm_fgINT8(dat,row,col,((fgINT8*) value));

  }else if(dat->type==FLGR_INT16) {
    flgr2d_get_data_no_norm_fgINT16(dat,row,col,((fgINT16*) value));

  }else if(dat->type==FLGR_INT32) {
    flgr2d_get_data_no_norm_fgINT32(dat,row,col,((fgINT32*) value));

  }else if(dat->type==FLGR_FLOAT32) {
    flgr2d_get_data_no_norm_fgFLOAT32(dat,row,col,((fgFLOAT32*) value));

  }else if(dat->type==FLGR_FLOAT64) {
    flgr2d_get_data_no_norm_fgFLOAT64(dat,row,col,((fgFLOAT64*) value));

  }else if(dat->type==FLGR_BIT) {
    flgr2d_get_data_no_norm_fgBIT(dat,row,col,((fgBIT*) value));

  }else {
    POST_ERROR("type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }
  
  return FLGR_RET_OK;
}






//! @}
